
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WebSocketOpCode {
    Text,
    Binary,
    Close,
    Ping,
    Pong,
    Other(u8),
}

impl WebSocketOpCode {
    pub fn from_u8(val: u8) -> Self {
        match val {
            0x1 => WebSocketOpCode::Text,
            0x2 => WebSocketOpCode::Binary,
            0x8 => WebSocketOpCode::Close,
            0x9 => WebSocketOpCode::Ping,
            0xA => WebSocketOpCode::Pong,
            other => WebSocketOpCode::Other(other),
        }
    }

    pub fn to_u8(self) -> u8 {
        match self {
            WebSocketOpCode::Text => 0x1,
            WebSocketOpCode::Binary => 0x2,
            WebSocketOpCode::Close => 0x8,
            WebSocketOpCode::Ping => 0x9,
            WebSocketOpCode::Pong => 0xA,
            WebSocketOpCode::Other(code) => code,
        }
    }
}
